<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="仓库" prop="storeId">
        <el-select v-model="queryParams.storeId" placeholder="请选择仓库" clearable>
          <el-option
            v-for="store in storeOptions"
            :key="store.storeId"
            :label="store.storeName"
            :value="store.storeId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="存货" prop="inventoryId">
        <el-select v-model="queryParams.inventoryId" placeholder="请选择存货" clearable>
          <el-option
            v-for="inventory in inventoryOptions"
            :key="inventory.inventoryId"
            :label="inventory.inventoryName"
            :value="inventory.inventoryId"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="onhandList">
      <el-table-column label="序号" align="center" prop="onhandId"/>
      <el-table-column label="仓库编码" align="center" prop="storeCode"/>
      <el-table-column label="仓库名称" align="center" prop="storeName"/>
      <el-table-column label="存货编码" align="center" prop="inventoryCode"/>
      <el-table-column label="存货名称" align="center" prop="inventoryName"/>
      <el-table-column label="现存量" align="center" prop="onhandNumber"/>
      <el-table-column label="冻结量" align="center" prop="freezeNumber"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listOnhand } from '@/api/stock/onhand'
import { listStore } from '@/api/archive/store'
import { listInventory } from '@/api/archive/inventory'

export default {
  name: 'Inout',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 现存量表格数据
      onhandList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storeId: undefined,
        inventoryId: undefined
      },
      storeOptions: [],
      inventoryOptions: []
    }
  },
  created() {
    this.getList()
    this.getStoreList()
    this.getInventoryList()
  },
  methods: {
    getStoreList() {
      listStore().then(res => {
        this.storeOptions = res.data
      })
    },
    getInventoryList() {
      listInventory().then(res => {
        this.inventoryOptions = res.data
      })
    },
    /** 查询入库列表 */
    getList() {
      this.loading = true
      listOnhand(this.queryParams).then(response => {
        this.onhandList = response.data
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
